'''
Created on Apr 17, 2010

@author: darkelf
'''

class BHObject(object):
    
    def __init__(self):
        object.__init__(self)
        self.is_body_object = True
    
    def get_html(self):
        return ""

class BasicHtmlText(BHObject):
    
    def __init__(self):
        BHObject.__init__(self)
        self.text_content = ''
    
    def set_content(self, content):
        self.text_content = content
    
    def get_html(self):
        return self.text_content

class BasicHtmlObject(BHObject):
    
    def __init__(self, name):
        BHObject.__init__(self)
        self.element_name = name
        self.childs = []
        self.attributes = {}
        
    def get_html(self):
        html = "<" + self.element_name + " "
        for attr in self.attributes:
            html+= attr + "=\"" + self.attributes[attr] + "\" "
        
        if len(self.childs) > 0:
            html+= ">"
            for child in self.childs:
                html+= child.get_html()
            html+= "</" + self.element_name + ">"
        else:
            html+= "/>"
        
        return html

class BasicHtmlPage(BHObject):
    
    def __init__(self):
        BHObject.__init__(self)
        self.HTML_TAG_NAME = "html"
        self.HEAD_TAG_NAME = "head"
        self.BODY_TAG_NAME = "body"
        self.head_elements = []
        self.body_elements = []
    
    def get_html(self):
        html = "<" + self.HTML_TAG_NAME + ">"
        html += "<" + self.HEAD_TAG_NAME
        
        if len(self.head_elements) > 0:
            html+=">"
            for h_child in self.head_elements:
                html+=h_child.get_html()
            html+="</" + self.HEAD_TAG_NAME +">"
        else:
            html+="/>"
        
        html+="<" + self.BODY_TAG_NAME
        
        if len(self.body_elements) > 0:
            html+=">"
            for b_child in self.body_elements:
                html+=b_child.get_html()
            html+="</" + self.BODY_TAG_NAME + ">"
        else:
            html+="/>"
        html+="</" + self.HTML_TAG_NAME+">"
        
        return html
    
class HtmlImage(BasicHtmlObject):
    
    def __init__(self):
        BasicHtmlObject.__init__(self, "img")        
    
    def set_src(self, src):
        self.attributes["src"] = src
        
    def get_src(self):
        return self.attributes["src"]
    
    def set_width(self, width):
        self.attributes["width"] = width
    
    def get_width(self):
        return self.attributes["width"]
    
    def set_height(self, height):
        self.attributes["height"] = height
    
    def get_height(self):
        return self.attributes["height"]

class HtmlFont(BasicHtmlObject):
    
    def __init__(self):
        BasicHtmlObject.__init__(self, "font")
        self.childs.append("")
    
    def set_text_content(self, content):
        self.childs[0] = content
        
    def get_text_content(self):
        return self.childs[0]
    
    def set_font_color(self, color):
        self.attributes["color"] = color
        
    def get_font_color(self):
        return self.attributes["color"]

class HtmlDiv(BasicHtmlObject):
    
    def __init__(self):
        BasicHtmlObject.__init__(self, "div")
    
    def set_width(self, width):
        self.attributes["width"] = width
    
    def get_width(self):
        return self.attributes["width"]
    
    def set_height(self, height):
        self.attributes["height"] = height
    
    def get_height(self):
        return self.attributes["height"]

class HtmlTable(BasicHtmlObject):
    
    def __init__(self):
        BasicHtmlObject.__init__(self, "table")
    
    def set_width(self, width):
        self.attributes["width"] = width
    
    def get_width(self):
        return self.attributes["width"]
    
    def set_height(self, height):
        self.attributes["height"] = height
    
    def get_height(self):
        return self.attributes["height"]
    
    def set_cellpadding(self, cellpadding):
        self.attributes["cellpadding"] = cellpadding
    
    def get_cellpadding(self):
        return self.attributes["cellpadding"]
    
    def set_cellspacing(self, cellspacing):
        self.attributes["cellspacing"] = cellspacing
        
    def get_cellspacing(self):
        return self.attributes["cellspacing"]

class HtmlTableRow(BasicHtmlObject):
    
    def __init__(self):
        BasicHtmlObject.__init__(self, "tr")
        
    def set_width(self, width):
        self.attributes["width"] = width
    
    def get_width(self):
        return self.attributes["width"]
    
    def set_height(self, height):
        self.attributes["height"] = height
    
    def get_height(self):
        return self.attributes["height"]

class HtmlTableData(BasicHtmlObject):
    
    def __init__(self):
        BasicHtmlObject.__init__(self, "td")
    
    def set_width(self, width):
        self.attributes["width"] = width
    
    def get_width(self):
        return self.attributes["width"]
    
    def set_height(self, height):
        self.attributes["height"] = height
    
    def get_height(self):
        return self.attributes["height"]